//----------------------------------------------------------------------------
// M A R I T I M E  R E S E A R C H  I N S T I T U T E  N E T H E R L A N D S
//----------------------------------------------------------------------------
// Copyright (C) 2011 - MARIN - All rights reserved - http://www.marin.nl
//----------------------------------------------------------------------------
// Program    : mermaid
// Module     : vbm
// File       : macros.h
// Author     : M.A. de Jong
//----------------------------------------------------------------------------

#ifndef MACROS_H
#define	MACROS_H

#include <sys/time.h>

#define START_CPU_TIMER(time, iter) \
{ \
    cudaThreadSynchronize(); \
	 gettimeofday(&start, NULL); \
    for (int t = 0; t < iter; t++) { \

#define STOP__CPU_TIMER(time, iter) \
    } \
    cudaThreadSynchronize(); \
	gettimeofday(&stop,  NULL); \
	time = (stop.tv_sec - start.tv_sec) + \
		1e-6 * (stop.tv_usec - start.tv_usec); \
    time /= iter; \
}

#define START_GPU_TIMER(time, iter) \
{ \
    cudaEvent_t start, stop; \
    cudaEventCreate(&start); \
    cudaEventCreate(&stop); \
    cudaEventRecord(start, 0); \
    for (unsigned int t = 0; t < iter; ++t) { \

#define STOP__GPU_TIMER(time, iter) \
    } \
    cudaEventRecord(stop, 0); \
    cudaEventSynchronize(stop); \
    cudaEventElapsedTime(&time, start, stop); \
    time /= (iter * 1e-3); \
}

#endif // MACROS_H
